package com.tubruk.todo;

import java.util.ArrayList;

import com.tubruk.todo.activity.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

//import android.view.;

public class MenuAdapter extends ArrayAdapter<PopMenu> {
	
	private ArrayList<PopMenu> items;
	
	public MenuAdapter(Context context, int textViewResourceId, ArrayList<PopMenu> items) {
        super(context, textViewResourceId, items);
    
        this.items = items;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.menu, null);
        }
		
		PopMenu item = items.get(position);
		
		
		if (item.getMenuImg() != PopMenu.NO_IMAGE) {
			ImageView img = (ImageView) v.findViewById(R.id.menuicon);
		 	img.setBackgroundResource(item.getMenuImg());
		}
	
		TextView text = (TextView) v.findViewById(R.id.menutext);
		text.setText(item.getMenuText());
		
		
		if (item.getBgColor() != PopMenu.NO_BGCOLOR){
			LinearLayout row = (LinearLayout) v.findViewById(R.id.menurow);
			row.setBackgroundColor(item.getBgColor());
			
			//lagi males ah
			text.setTextColor(Global.PRIORITY_COLOR_NONE);
		}
		return v;
	}

}
